package com.topisv.tms.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.topisv.tms.entity.GoodsShelf;
import com.topisv.tms.repository.GoodsShelfDao;

//Spring Bean的标识.
@Component
//默认将类中的所有public函数纳入事务管理.
@Transactional(readOnly = true)
public class GoodsShelfService {
	private GoodsShelfDao goodsShelfDao;
	
	@Autowired
	public void setGoodsShelfDao(GoodsShelfDao goodsShelfDao) {
		this.goodsShelfDao = goodsShelfDao;
	}

	
	public GoodsShelf getGoodsShelf(Long id) {
		return goodsShelfDao.findOne(id);
	}
	
	public GoodsShelf findByCode(String code) {
		return goodsShelfDao.findByCode(code);
	}
	
	@Transactional(readOnly = false)
	public void saveGoodsShelf(GoodsShelf entity) {
		goodsShelfDao.save(entity);
	}
	
	@Transactional(readOnly = false)
	public void deleteGoodsShelf(Long id) {
		goodsShelfDao.delete(id);
	}
	
	public List<GoodsShelf> getAllGoodsShelf() {
		return (List<GoodsShelf>) goodsShelfDao.findAll();
	}
	
}
